//
//  Database+Extensions.swift
//  GlassDatabase
//
//  Created by 李然 on 2023/5/19.
//

import Foundation
import SwiftDate
import RealmSwift

public extension Date {
    
    /// 计算天数差
    /// - Parameter date: 日期
    /// - Returns: 差额多少天
    static func dayComponents(of startDate: Date, to date: Date) -> Int {
        
        // 算出来date距离今天多少天
        let calendar = Calendar.current
        let endDate = date
        
        var dateComponents = calendar.dateComponents([.day], from: endDate, to: startDate).day!
        if dateComponents < 0 {
            dateComponents = 0
        }
        return dateComponents
    }
}
